home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
sos3-2.lha
/
src
/
cfe
/
cfe.y
< prev
Wrap
Text File
|
1992-01-23
|
19KB
|
829 lines
/* --------------------------------------------------------------------------
* Copyright 1992 by Forschungszentrum Informatik (FZI)
*
* You can use and distribute this software under the terms of the licence
* you should have received along with this program.
* If not or if you want additional information, write to
* Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
* D-7500 Karlsruhe 1, Germany.
* --------------------------------------------------------------------------
*/
%token name_tok
%token number_tok
%token abstract_tok
%token class_tok
%token definite_tok
%token enum_tok
%token extern_tok
%token friend_tok
%token local_tok
%token operator_tok
%token private_tok
%token protected_tok
%token public_tok
%token schema_tok
%token set_tok
%token static_tok
%token typedef_tok
%token union_tok
%token with_tok
%token l_abr_tok
%token r_abr_tok
%token l_br_tok
%token r_br_tok
%token l_brc_tok
%token r_brc_tok
%token l_par_tok
%token r_par_tok
%token ampersand_tok
%token ampersand_assign_tok
%token and_tok
%token assign_tok
%token bar_tok
%token bar_assign_tok
%token circumflex_tok
%token circumflex_assign_tok
%token colon_tok
%token comma_tok
%token equal_tok
%token exclam_tok
%token greater_equal_tok
%token less_equal_tok
%token minus_tok
%token minus_assign_tok
%token not_equal_tok
%token or_tok
%token percent_tok
%token percent_assign_tok
%token plus_tok
%token plus_assign_tok
%token rshift_assign_tok
%token lshift_assign_tok
%token slash_tok
%token slash_assign_tok
%token star_tok
%token star_assign_tok
%token semicolon_tok
%type <imp> imports
%type <imp> import_names
%type <s> name_tok
%type <s> name_tok_or_keyword
%type <str> name
%type <str> name1
%type <str_l> names
%type <etd> enumeration_declaration
%type <ctd> class_declaration
%type <tn_l> super_classes
%type <utd> union_declaration
%type <ttd> typedef_declaration
%type <xtd> extern_declaration
%type <i> extern_size
%type <gp_l> gen_params
%type <gp_l> gen_params_1
%type <gp> gen_param
%type <tn_l> type_names_with_params
%type <tn> type_name_with_params
%type <mk> method_kind_spec
%type <md> function_method
%type <str> function_name
%type <str> operator
%type <str> operator_string
%type <par_l> opt_parameters
%type <par_l> parameters
%type <par_l> parameters_1
%type <par> parameter
%type <exp> default_expr
%type <tn> type_name
%type <tn> type_name1
%type <tn_l> type_names
%type <exp> expr
%type <exp_l> exprs
%type <exp_l> exprs1
%type <i> number_tok
%type <ie> number
%type <id> identifier
%type <tn> generic_instantiation
%type <b> reference
%{
#include <libc.h>
#include "sys.h"
#include "smg.h"
#include "cfe_err.h"
#include "mta_sos.h"
#include "cfe.h"
#include "cfe_yacc.h"
typedef union {
sos_Bool b;
sos_Int i;
sos_Cstring s;
sos_Imports imp;
sos_String str;
sos_String_List str_l;
sos_Schema_type_List td_l;
sos_Enum_type etd;
sos_Class_type ctd;
sos_Gen_param gp;
sos_Gen_param_List gp_l;
sos_Param par;
sos_Param_List par_l;
sos_Method_kind mk;
sos_Method_List md_l;
sos_Method md;
sos_Union_type utd;
sos_Typedef_type ttd;
sos_Extern_type xtd;
sos_Type_name tn;
sos_Type_name_List tn_l;
sos_Expr exp;
sos_Int_expr ie;
sos_Identifier id;
sos_Expr_List exp_l;
} YYSTYPE;
static sos_Type_name cfe_fct_or_comp_type;
static sos_Class_type cfe_ct;
static sos_Bool cfe_is_full_type;
static sos_Bool cfe_is_operator;
static sos_Bool cfe_method_is_abstract,
cfe_method_is_definite,
cfe_method_is_local,
cfe_method_is_static,
cfe_method_is_value;
static sos_Method_kind cfe_method_kind, cfe_set_method_kind;
static sos_Int cfe_component_offset;
static sos_Type_name_List cfe_gen_insts;
#include "cfe_lex.h"
%}
%%
%{
#include <malloc.h>
%}
schema_module
: { cfe_cnt = sos_Container::create ();
cfe_ct = sos_Class_type::make (NO_OBJECT);
cfe_schema = sos_Schema_module::create (cfe_cnt);
cfe_gen_insts = sos_Type_name_List::create (TEMP_CONTAINER);
}
imports
schema_tok
name
{ cfe_schema.set_imports ($2);
cfe_schema.set_name ($4);
cfe_init($4, $2);
}
l_brc_tok
type_declarations
r_brc_tok
opt_semicolon
{ cfe_check_schema ();
cfe_check_generic_instantiations (cfe_gen_insts);
cfe_finalize();
}
| error
;
imports : extern_import
{ $$ = sos_Imports::create (cfe_cnt); }
| with_tok
import_names
opt_semicolon
extern_import
{ $$ = $2; }
;
import_names
: name1
{ $$ = sos_Imports::create (cfe_cnt);
cfe_import_module ($$, $1);
}
| import_names
comma_tok
name1
{ $$ = $1;
cfe_import_module ($$, $3);
}
;
extern_import : { cfe_schema.set_has_external_import (FALSE); }
| with_tok
extern_tok
semicolon_tok
{ cfe_schema.set_has_external_import (TRUE); }
;
opt_semicolon :
| semicolon_tok
;
type_declarations
:
| type_declarations
type_declaration
| error
;
type_declaration
: enumeration_declaration
| class_declaration
| union_declaration
| typedef_declaration
semicolon_tok
| extern_declaration
semicolon_tok
| typedef_tok generic_instantiation
semicolon_tok
;
enumeration_declaration
: enum_tok
name
l_brc_tok
names
r_brc_tok
opt_semicolon
{ cfe_check_type ($2);
$$ = sos_Enum_type::create (cfe_cnt);
$$.set_name($2);
$$.set_object_size (cfe_enum_size ($4.card()));
$$.set_literals($4);
cfe_type_tab.insert ($2, $$);
cfe_types.append ($$);
}
;
class_declaration
: class_tok
name
{ cfe_ct = sos_Class_type::create (cfe_cnt);
cfe_ct.set_name ($2);
cfe_make_class_type ($2, cfe_ct);
cfe_type_tab.insert ($2, cfe_ct);
}
gen_params
{ cfe_ct.set_gen_params($4); }
opt_parameters
{ cfe_ct.set_create_params($6); }
super_classes
{ cfe_ct.set_super_classes($8);
cfe_set_super_closure (cfe_ct);
}
l_brc_tok
{ cfe_ct.set_friends
(sos_Type_name_List::create (cfe_cnt, FALSE));
cfe_init_methods (cfe_ct);
cfe_component_offset = 0;
}
method_declarations
r_brc_tok
opt_semicolon
{ $$ = cfe_ct;
cfe_set_offsets_and_size (cfe_ct, cfe_component_offset);
cfe_set_inherited_methods (cfe_ct);
cfe_complete_methods (cfe_ct);
$$.set_generated_from
(sos_Generic_instantiation::make(NO_OBJECT));
cfe_set_root_name (cfe_ct);
cfe_types.append ($$);
cfe_ct = sos_Class_type::make (NO_OBJECT);
}
;
gen_params : { $$ = sos_Gen_param_List::make (NO_OBJECT); }
| l_abr_tok
gen_params_1
r_abr_tok
{ if (cfe_is_full_type)
cfe_error (err_USE, err_CFE_FULL_GENERIC);
$$ = $2;
}
;
gen_params_1 : gen_param
{ $$ = sos_Gen_param_List::create (cfe_cnt, FALSE);
$$.append ($1);
}
| gen_params_1
comma_tok
gen_param
{ if (cfe_lookup_gen_params ($3.get_name(), $1) != NO_OBJECT)
cfe_error (err_USE, err_CFE_AMBIGUOUS_GEN_PARAMS);
$1.append ($3);
$$ = $1;
}
;
gen_param : name
{ $$ = sos_Gen_param::create (cfe_cnt);
$$.set_name ($1);
$$.set_super_class (sos_Type_name::make(NO_OBJECT));
}
| name
colon_tok
type_name
{ $$ = sos_Gen_param::create (cfe_cnt);
$$.set_name ($1);
$$.set_super_class ($3);
}
;
opt_parameters
: { $$ = sos_Param_List::make (NO_OBJECT);
}
| parameters
;
super_classes
: { $$ = sos_Type_name_List::create (cfe_cnt, FALSE);
#ifdef ATT
if (cfe_ct.operator!=(cfe_get_object_type()))
#else
if (cfe_ct != cfe_get_object_type())
#endif
$$.append (cfe_get_object_type());
}
| colon_tok
type_names_with_params
{ cfe_check_super_classes (cfe_ct, $2);
$$ = $2;
}
;
type_names_with_params : type_name_with_params
{ $$ = sos_Type_name_List::create (cfe_cnt, FALSE);
$$.append ($1);
}
| type_names_with_params
comma_tok
type_name_with_params
{ $1.append ($3);
$$ = $1;
}
;
type_name_with_params
: type_name
| type_name
l_par_tok
exprs
r_par_tok
{ sos_Type_with_params twp = sos_Type_with_params::create (cfe_cnt);
twp.set_type_name ($1);
twp.set_params ($3);
$$ = twp;
}
;
method_declarations
: { cfe_method_kind = sos_PRIVATE;
cfe_set_method_kind = sos_PRIVATE;
}
| method_declarations
{ cfe_method_is_abstract = FALSE;
cfe_method_is_definite = FALSE;
cfe_method_is_local = FALSE;
cfe_method_is_static = FALSE;
cfe_method_is_value = FALSE;
}
method_declaration
;
method_declaration
: fct_or_comp_type function_method
| fct_or_comp_type comp_methods
| friend
| method_kind_spec
{ cfe_method_kind = $1; }
set_method_kind_spec
colon_tok
| error
;
fct_or_comp_type : fct_or_comp_kind
type_name
{ cfe_fct_or_comp_type = $2; }
;
fct_or_comp_kind
: abstract_tok
{ cfe_method_is_abstract = TRUE; }
| definite_tok
local_or_value_spec
{ cfe_method_is_definite = TRUE; }
| static_tok
{ cfe_method_is_static = TRUE; }
| local_or_value_spec
;
local_or_value_spec
:
| local_tok
{ cfe_method_is_local = TRUE; }
| exclam_tok
{ cfe_method_is_value = TRUE; }
;
method_kind_spec :
private_tok
{ $$ = sos_PRIVATE; }
| protected_tok
{ $$ = sos_PROTECTED; }
| public_tok
{ $$ = sos_PUBLIC; }
;
set_method_kind_spec :
{ cfe_set_method_kind = cfe_method_kind; }
| comma_tok
method_kind_spec
set_tok
{ cfe_set_method_kind = $2; }
;
function_method
: function_name
parameters
semicolon_tok
{ if (cfe_method_is_definite)
cfe_error(err_WNG, err_CFE_NO_DEFINITE_FUNCS);
if (cfe_method_is_local)
cfe_error(err_USE, err_CFE_NO_LOCAL_FUNCS);
if (cfe_method_is_value)
cfe_error(err_USE, err_CFE_NO_VALUE_FUNCS);
$$ = sos_Method::create (cfe_cnt);
$$.set_name ($1);
$$.set_is_abstract (cfe_method_is_abstract);
if (cfe_method_is_abstract)
cfe_ct.set_is_abstract (TRUE);
$$.set_is_static (cfe_method_is_static);
$$.set_is_operator (cfe_is_operator);
$$.set_is_predefined (FALSE);
$$.set_params ($2);
$$.set_result_type (cfe_fct_or_comp_type);
$$.set_kind (cfe_method_kind);
$$.set_defined_in (cfe_ct);
$$.set_generated_from (sos_Method::make(NO_OBJECT));
$$.set_impls (sos_Method_impl_List::make (NO_OBJECT));
cfe_append_method (cfe_ct, $$);
}
;
function_name : name
{ $$ = $1;
cfe_is_operator = FALSE;
}
| operator
{ $$ = $1;
cfe_is_operator = TRUE;
}
;
operator : operator_tok
operator_string
{ $$ = $2; }
;
operator_string
: star_tok
{ $$ = smg_String ("*").make_String (cfe_cnt); }
| slash_tok
{ $$ = smg_String ("/").make_String (cfe_cnt); }
| percent_tok
{ $$ = smg_String ("%").make_String (cfe_cnt); }
| plus_tok
{ $$ = smg_String ("+").make_String (cfe_cnt); }
| minus_tok
{ $$ = smg_String ("-").make_String (cfe_cnt); }
| r_abr_tok r_abr_tok
{ $$ = smg_String (">>").make_String (cfe_cnt); }
| l_abr_tok l_abr_tok
{ $$ = smg_String ("<<").make_String (cfe_cnt); }
| r_abr_tok
{ $$ = smg_String (">").make_String (cfe_cnt); }
| l_abr_tok
{ $$ = smg_String ("<").make_String (cfe_cnt); }
| equal_tok
{ $$ = smg_String ("==").make_String (cfe_cnt); }
| not_equal_tok
{ $$ = smg_String ("!=").make_String (cfe_cnt); }
| less_equal_tok
{ $$ = smg_String ("<=").make_String (cfe_cnt); }
| greater_equal_tok
{ $$ = smg_String (">=").make_String (cfe_cnt); }
| ampersand_tok
{ $$ = smg_String ("&").make_String (cfe_cnt); }
| circumflex_tok
{ $$ = smg_String ("^").make_String (cfe_cnt); }
| bar_tok
{ $$ = smg_String ("|").make_String (cfe_cnt); }
| and_tok
{ $$ = smg_String ("&&").make_String (cfe_cnt); }
| or_tok
{ $$ = smg_String ("||").make_String (cfe_cnt); }
| assign_tok
{ $$ = smg_String ("=").make_String (cfe_cnt); }
| plus_assign_tok
{ $$ = smg_String ("+=").make_String (cfe_cnt); }
| minus_assign_tok
{ $$ = smg_String ("-=").make_String (cfe_cnt); }
| star_assign_tok
{ $$ = smg_String ("*=").make_String (cfe_cnt); }
| slash_assign_tok
{ $$ = smg_String ("/=").make_String (cfe_cnt); }
| percent_assign_tok
{ $$ = smg_String ("%=").make_String (cfe_cnt); }
| circumflex_assign_tok
{ $$ = smg_String ("^=").make_String (cfe_cnt); }
| ampersand_assign_tok
{ $$ = smg_String ("&=").make_String (cfe_cnt); }
| bar_assign_tok
{ $$ = smg_String ("|=").make_String (cfe_cnt); }
| rshift_assign_tok
{ $$ = smg_String (">>=").make_String (cfe_cnt); }
| lshift_assign_tok
{ $$ = smg_String ("<<=").make_String (cfe_cnt); }
| l_par_tok r_par_tok
{ $$ = smg_String ("()").make_String (cfe_cnt); }
| l_br_tok r_br_tok
{ $$ = smg_String ("[]").make_String (cfe_cnt); }
;
parameters
: l_par_tok
r_par_tok
{ $$ = sos_Param_List::create (cfe_cnt, FALSE); }
| l_par_tok
parameters_1
r_par_tok
{ $$ = $2; }
;
parameters_1
: parameter
{ $$ = sos_Param_List::create (cfe_cnt, FALSE);
$$.append ($1);
}
| parameters_1
comma_tok
parameter
{ $1.append ($3);
$$ = $1;
}
;
parameter
: type_name
reference
name
default_expr
{ $$ = sos_Param::create (cfe_cnt);
$$.set_name ($3);
$$.set_type_name ($1);
$$.set_default_expr ($4);
$$.set_is_ref ($2);
}
| type_name
reference
default_expr
{ $$ = sos_Param::create (cfe_cnt);
$$.set_name (sos_String::make (NO_OBJECT));
$$.set_type_name ($1);
$$.set_default_expr ($3);
$$.set_is_ref ($2);
}
;
reference
: { $$ = FALSE; }
| ampersand_tok
{ $$ = TRUE; }
;
default_expr
: { $$ = sos_Expr::make (NO_OBJECT); }
| assign_tok
expr
{ $$ = $2; }
;
comp_methods
: comp_names
semicolon_tok
;
comp_names : comp_name
| comp_names
comma_tok
comp_name
;
comp_name : name1
default_expr
{ if (cfe_method_is_definite)
cfe_error(err_WNG, err_CFE_NO_DEFINITE_COMPS);
if (cfe_method_is_static)
cfe_error(err_USE, err_CFE_NO_STATIC_COMPS);
if (cfe_method_is_value)
cfe_error(err_USE, err_CFE_NO_VALUE_COMPS);
cfe_append_comp_methods
(cfe_ct, cfe_fct_or_comp_type, $1, $2,
cfe_method_kind, cfe_set_method_kind,
cfe_method_is_value, cfe_method_is_local,
cfe_component_offset);
if ($2 != NO_OBJECT)
cfe_ct.set_has_init_comps (TRUE);
}
;
friend : friend_tok
class_tok
type_name1
semicolon_tok
{ cfe_ct.get_friends().append ($3);
}
;
union_declaration
: union_tok
name
{ cfe_check_type ($2); }
l_brc_tok
type_names
r_brc_tok
opt_semicolon
{ $$ = sos_Union_type::create (cfe_cnt);
$$.set_name ($2);
$$.set_uniteds ($5);
cfe_type_tab.insert ($2, $$);
cfe_types.append ($$);
}
;
typedef_declaration
: typedef_tok
type_name
name
{ $$ = sos_Typedef_type::create (cfe_cnt);
$$.set_name ($3);
$$.set_type_name ($2);
if ($2.make_base_type().has_type (sos_Class_type_type))
{ sos_Class_type ct = sos_Class_type::make ($2.make_base_type());
cfe_make_class_type ($3, ct);
}
else
cfe_check_type ($3);
cfe_type_tab.insert ($3, $$);
cfe_types.append ($$);
}
;
extern_declaration
: extern_tok
name
extern_size
{ cfe_check_type ($2);
$$ = sos_Extern_type::create (cfe_cnt);
$$.set_name ($2);
$$.set_object_size ($3);
cfe_schema.set_has_external_types (TRUE);
cfe_type_tab.insert ($2, $$);
cfe_types.append ($$);
}
;
extern_size : { $$ = 4; }
| l_par_tok
number_tok
r_par_tok
{ $$ = $2;
if ($2 > SOS_ID_SIZE)
{ cfe_error (err_USE, err_CFE_INVALID_EXT_SIZE); }
}
;
type_name : type_name1
{ $$ = $1;
cfe_check_no_generic ($1);
}
;
type_name1 : name1
{ $$ = cfe_lookup_type_name (cfe_ct, $1); }
| generic_instantiation
{ $$ = $1; }
;
exprs : { $$ = sos_Expr_List::create (cfe_cnt, FALSE); }
| exprs1
;
exprs1 : expr
{ $$ = sos_Expr_List::create (cfe_cnt, FALSE);
$$.append ($1);
}
| exprs1
comma_tok
expr
{ $1.append ($3);
$$ = $1;
}
;
expr : identifier
{ $$ = $1; }
| number
{ $$ = $1; }
;
identifier : name
{ $$ = sos_Identifier::create (cfe_cnt);
$$.set_id($1);
}
;
number : number_tok
{ $$ = sos_Int_expr::create (cfe_cnt);
$$.set_value($1);
}
;
generic_instantiation
: name1
l_abr_tok
type_names
r_abr_tok
{ $$ = cfe_lookup_generic_instantiation ($1, $3, cfe_types);
cfe_gen_insts.append ($$);
}
;
type_names
: type_name
{ $$ = sos_Type_name_List::create (cfe_cnt, FALSE);
$$.append ($1);
}
| type_names
comma_tok
type_name
{ $1.append ($3);
$$ = $1;
}
;
name1 : name_tok_or_keyword
{ $$ = smg_String ($1).make_String (TEMP_CONTAINER);
delete $1;
}
;
names : name
{ $$ = sos_String_List::create (cfe_cnt, FALSE);
$$.append ($1);
}
| names
comma_tok
name
{ $1.append ($3);
$$ = $1;
}
;
name : name_tok_or_keyword
{ $$ = smg_String ($1).make_String (cfe_cnt);
delete $1;
}
;
name_tok_or_keyword : name_tok
| set_tok
{ $$ = strdup ("set"); }
;
%%
void yyerror (err_msg s) {cfe_error (err_USE, s);}
void yyecho () {if (cfe_echo_flag) ECHO;}